guint fade_edges : 1;
- float vfade_offset;
- float hfade_offset;
+ ClutterMargin fade_margins;
};
G_DEFINE_TYPE (StScrollViewFade,
enum {
PROP_0,
- PROP_VFADE_OFFSET,
- PROP_HFADE_OFFSET,
+ PROP_FADE_MARGINS,
PROP_FADE_EDGES,
N_PROPS
if (h_scroll_visible)
fade_area_bottomright[1] -= clutter_actor_get_height (hscroll);
+ if (self->fade_margins.left < 0)
+ fade_area_topleft[0] -= ABS (self->fade_margins.left);
+ if (self->fade_margins.right < 0)
+ fade_area_bottomright[0] += ABS (self->fade_margins.right);
+ if (self->fade_margins.top < 0)
+ fade_area_topleft[1] -= ABS (self->fade_margins.top);
+ if (self->fade_margins.bottom < 0)
+ fade_area_bottomright[1] += ABS (self->fade_margins.bottom);
+
st_adjustment_get_values (self->vadjustment, &value, &lower, &upper, NULL, NULL, &page_size);
value = (value - lower) / (upper - page_size - lower);
clutter_shader_effect_set_uniform (shader, "fade_edges_top", G_TYPE_INT, 1, self->fade_edges ? value >= 0.0 : value > 0.0);
clutter_shader_effect_set_uniform (shader, "fade_edges_left", G_TYPE_INT, 1, self->fade_edges ? value >= 0.0 : value > 0.0);
clutter_shader_effect_set_uniform (shader, "fade_edges_right", G_TYPE_INT, 1, self->fade_edges ? value <= 1.0 : value < 1.0);
- clutter_shader_effect_set_uniform (shader, "vfade_offset", G_TYPE_FLOAT, 1, self->vfade_offset);
- clutter_shader_effect_set_uniform (shader, "hfade_offset", G_TYPE_FLOAT, 1, self->hfade_offset);
+ clutter_shader_effect_set_uniform (shader, "fade_offset_top", G_TYPE_FLOAT, 1, ABS (self->fade_margins.top));
+ clutter_shader_effect_set_uniform (shader, "fade_offset_bottom", G_TYPE_FLOAT, 1, ABS (self->fade_margins.bottom));
+ clutter_shader_effect_set_uniform (shader, "fade_offset_left", G_TYPE_FLOAT, 1, ABS (self->fade_margins.left));
+ clutter_shader_effect_set_uniform (shader, "fade_offset_right", G_TYPE_FLOAT, 1, ABS (self->fade_margins.right));
clutter_shader_effect_set_uniform (shader, "tex", G_TYPE_INT, 1, 0);
clutter_shader_effect_set_uniform (shader, "height", G_TYPE_FLOAT, 1, clutter_actor_get_height (self->actor));
clutter_shader_effect_set_uniform (shader, "width", G_TYPE_FLOAT, 1, clutter_actor_get_width (self->actor));
}
static void
-st_scroll_view_vfade_set_offset (StScrollViewFade *self,
- float fade_offset)
-{
- if (self->vfade_offset == fade_offset)
- return;
-
- g_object_freeze_notify (G_OBJECT (self));
-
- self->vfade_offset = fade_offset;
-
- if (self->actor != NULL)
- clutter_actor_queue_redraw (self->actor);
-
- g_object_notify_by_pspec (G_OBJECT (self), props[PROP_VFADE_OFFSET]);
- g_object_thaw_notify (G_OBJECT (self));
-}
-
-static void
-st_scroll_view_hfade_set_offset (StScrollViewFade *self,
- float fade_offset)
+st_scroll_view_set_fade_margins (StScrollViewFade *self,
+ ClutterMargin *fade_margins)
{
- if (self->hfade_offset == fade_offset)
+ if (self->fade_margins.left == fade_margins->left &&
+ self->fade_margins.right == fade_margins->right &&
+ self->fade_margins.top == fade_margins->top &&
+ self->fade_margins.bottom == fade_margins->bottom)
return;
- g_object_freeze_notify (G_OBJECT (self));
-
- self->hfade_offset = fade_offset;
+ self->fade_margins = *fade_margins;
if (self->actor != NULL)
clutter_actor_queue_redraw (self->actor);
- g_object_notify_by_pspec (G_OBJECT (self), props[PROP_HFADE_OFFSET]);
- g_object_thaw_notify (G_OBJECT (self));
+ g_object_notify_by_pspec (G_OBJECT (self), props[PROP_FADE_MARGINS]);
}
static void
switch (prop_id)
{
- case PROP_VFADE_OFFSET:
- st_scroll_view_vfade_set_offset (self, g_value_get_float (value));
- break;
- case PROP_HFADE_OFFSET:
- st_scroll_view_hfade_set_offset (self, g_value_get_float (value));
+ case PROP_FADE_MARGINS:
+ st_scroll_view_set_fade_margins (self, g_value_get_boxed (value));
break;
case PROP_FADE_EDGES:
st_scroll_view_fade_set_fade_edges (self, g_value_get_boolean (value));
switch (prop_id)
{
- case PROP_HFADE_OFFSET:
- g_value_set_float (value, self->hfade_offset);
- break;
- case PROP_VFADE_OFFSET:
- g_value_set_float (value, self->vfade_offset);
+ case PROP_FADE_MARGINS:
+ g_value_set_boxed (value, &self->fade_margins);
break;
case PROP_FADE_EDGES:
g_value_set_boolean (value, self->fade_edges);
offscreen_class->paint_target = st_scroll_view_fade_paint_target;
/**
- * StScrollViewFade:vfade-offset:
- *
- * The height of area which is faded at the top and bottom edges of the
- * #StScrollViewFade.
- */
- props[PROP_VFADE_OFFSET] =
- g_param_spec_float ("vfade-offset",
- "Vertical Fade Offset",
- "The height of the area which is faded at the edge",
- 0.f, G_MAXFLOAT, DEFAULT_FADE_OFFSET,
- ST_PARAM_READWRITE);
-
- /**
- * StScrollViewFade:hfade-offset:
+ * StScrollViewFade:fade-margins:
*
- * The height of area which is faded at the left and right edges of the
- * #StScrollViewFade.
+ * The margins widths that are faded.
*/
- props[PROP_HFADE_OFFSET] =
- g_param_spec_float ("hfade-offset",
- "Horizontal Fade Offset",
- "The width of the area which is faded at the edge",
- 0.f, G_MAXFLOAT, DEFAULT_FADE_OFFSET,
+ props[PROP_FADE_MARGINS] =
+ g_param_spec_boxed ("fade-margins",
+ "Fade margins",
+ "The margin widths that are faded",
+ CLUTTER_TYPE_MARGIN,
ST_PARAM_READWRITE);
/**
static void
st_scroll_view_fade_init (StScrollViewFade *self)
{
- self->vfade_offset = DEFAULT_FADE_OFFSET;
- self->hfade_offset = DEFAULT_FADE_OFFSET;
+ self->fade_margins = (ClutterMargin) {
+ DEFAULT_FADE_OFFSET,
+ DEFAULT_FADE_OFFSET,
+ DEFAULT_FADE_OFFSET,
+ DEFAULT_FADE_OFFSET,
+ };
}
/**
uniform sampler2D tex;
uniform float height;
uniform float width;
-uniform float vfade_offset;
-uniform float hfade_offset;
+uniform float fade_offset_top;
+uniform float fade_offset_bottom;
+uniform float fade_offset_left;
+uniform float fade_offset_right;
uniform bool fade_edges_top;
uniform bool fade_edges_right;
uniform bool fade_edges_bottom;
float y = height * cogl_tex_coord_in[0].y;
float x = width * cogl_tex_coord_in[0].x;
- /*
- * We cannot just return here due to a bug in llvmpipe see:
- * https://bugzilla.freedesktop.org/show_bug.cgi?id=62357
- */
if (x > fade_area_topleft[0] && x < fade_area_bottomright[0] &&
- y > fade_area_topleft[1] && y < fade_area_bottomright[1]) {
+ y > fade_area_topleft[1] && y < fade_area_bottomright[1])
+ {
float ratio = 1.0;
- float fade_top_start = fade_area_topleft[1] + vfade_offset;
- float fade_left_start = fade_area_topleft[0] + hfade_offset;
- float fade_bottom_start = fade_area_bottomright[1] - vfade_offset;
- float fade_right_start = fade_area_bottomright[0] - hfade_offset;
- bool fade_top = y < vfade_offset && fade_edges_top;
+ float fade_top_start = fade_area_topleft[1] + fade_offset_top;
+ float fade_left_start = fade_area_topleft[0] + fade_offset_left;
+ float fade_bottom_start = fade_area_bottomright[1] - fade_offset_bottom;
+ float fade_right_start = fade_area_bottomright[0] - fade_offset_right;
+ bool fade_top = y < fade_top_start && fade_edges_top;
bool fade_bottom = y > fade_bottom_start && fade_edges_bottom;
bool fade_left = x < fade_left_start && fade_edges_left;
bool fade_right = x > fade_right_start && fade_edges_right;
- float vfade_scale = height / vfade_offset;
if (fade_top) {
ratio *= (fade_area_topleft[1] - y) / (fade_area_topleft[1] - fade_top_start);
}
ratio *= (fade_area_bottomright[1] - y) / (fade_area_bottomright[1] - fade_bottom_start);
}
- float hfade_scale = width / hfade_offset;
if (fade_left) {
ratio *= (fade_area_topleft[0] - x) / (fade_area_topleft[0] - fade_left_start);
}
}
cogl_color_out *= ratio;
+ } else {
+ cogl_color_out *= 0;
}
}
/**
* st_scroll_view_update_fade_effect:
* @scroll: a #StScrollView
- * @vfade_offset: The length of the vertical fade effect, in pixels.
- * @hfade_offset: The length of the horizontal fade effect, in pixels.
+ * @fade_margins: a #ClutterMargin defining the vertical fade effects, in pixels.
*
- * Sets the height of the fade area area in pixels. A value of 0
+ * Sets the fade effects in all four edges of the view. A value of 0
* disables the effect.
*/
void
-st_scroll_view_update_fade_effect (StScrollView *scroll,
- float vfade_offset,
- float hfade_offset)
+st_scroll_view_update_fade_effect (StScrollView *scroll,
+ ClutterMargin *fade_margins)
{
StScrollViewPrivate *priv = ST_SCROLL_VIEW (scroll)->priv;
- /* A fade amount of more than 0 enables the effect. */
- if (vfade_offset > 0. || hfade_offset > 0.)
+ /* A fade amount of other than 0 enables the effect. */
+ if (fade_margins->left != 0. || fade_margins->right != 0. ||
+ fade_margins->top != 0. || fade_margins->bottom != 0.)
{
- if (priv->fade_effect == NULL) {
- priv->fade_effect = g_object_new (ST_TYPE_SCROLL_VIEW_FADE, NULL);
+ if (priv->fade_effect == NULL)
+ {
+ priv->fade_effect = g_object_new (ST_TYPE_SCROLL_VIEW_FADE, NULL);
- clutter_actor_add_effect_with_name (CLUTTER_ACTOR (scroll), "fade",
- CLUTTER_EFFECT (priv->fade_effect));
- }
+ clutter_actor_add_effect_with_name (CLUTTER_ACTOR (scroll), "fade",
+ CLUTTER_EFFECT (priv->fade_effect));
+ }
g_object_set (priv->fade_effect,
- "vfade-offset", vfade_offset,
- NULL);
- g_object_set (priv->fade_effect,
- "hfade-offset", hfade_offset,
+ "fade-margins", fade_margins,
NULL);
}
else
{
- if (priv->fade_effect != NULL) {
- clutter_actor_remove_effect (CLUTTER_ACTOR (scroll), CLUTTER_EFFECT (priv->fade_effect));
- priv->fade_effect = NULL;
- }
+ if (priv->fade_effect != NULL)
+ {
+ clutter_actor_remove_effect (CLUTTER_ACTOR (scroll),
+ CLUTTER_EFFECT (priv->fade_effect));
+ priv->fade_effect = NULL;
+ }
}
clutter_actor_queue_redraw (CLUTTER_ACTOR (scroll));
StThemeNode *theme_node = st_widget_get_theme_node (widget);
gdouble vfade_offset = st_theme_node_get_length (theme_node, "-st-vfade-offset");
gdouble hfade_offset = st_theme_node_get_length (theme_node, "-st-hfade-offset");
- st_scroll_view_update_fade_effect (self, vfade_offset, hfade_offset);
+ st_scroll_view_update_fade_effect (self,
+ &(ClutterMargin) {
+ .top = vfade_offset,
+ .bottom = vfade_offset,
+ .left = hfade_offset,
+ .right = hfade_offset,
+ });
st_widget_style_changed (ST_WIDGET (priv->hscroll));
st_widget_style_changed (ST_WIDGET (priv->vscroll));